﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Twi.COMMON.Core
{
    /**
     * Copyright: ©2015 踏影软件开发工作室【Tyingsoft、Twilight】版权所有
     * Author: feitianxinhong
     * Create Date: 2015-04-22
     * Description: config配置文件辅助类
     *
     */
    public class TwiCfgFileHelper
    {
        /// <summary>
        /// 获取根节点
        /// </summary>
        /// <param name="fileFullPath">完整路径</param>
        /// <returns></returns>
        public static XmlElement GetRootNode(string fileFullPath)
        {
            TwiPathHelper.ExistFile(fileFullPath, true);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(fileFullPath);
            XmlElement root = xmlDoc.DocumentElement;
            return root;
        }

        /// <summary>
        /// 选择匹配XPath表达式的第一个节点
        /// </summary>
        /// <param name="fileFullPath">文件完整路径</param>
        /// <param name="xpath">xpth语法路径</param>
        /// <returns></returns>
        public static XmlElement SelectSingleNode(string fileFullPath, string xpath) 
        {
            XmlElement root = GetRootNode(fileFullPath);            
            XmlElement node = (XmlElement)root.SelectSingleNode(xpath);
            return node;
        }
    }
}
